var express = require('express');
var router = express.Router();

// 导入并配置 log4js
const log4js = require('log4js');
log4js.configure({
  appenders: { myapp: { type: 'file', filename: 'myapp.log' } },
  categories: { default: { appenders: ['myapp'], level: 'info' } },
});
const logger = log4js.getLogger('myapp');

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('=== node log server ===');
});

router.post('/', function(req, res, next) {
  // console.log('req', JSON.stringify(Object.keys(req)));
  console.log('req', JSON.stringify(req.headers));
  console.log('req', JSON.stringify(req.body));

  logger.info(req.body.msg);

  res.send('=== OK ===');
});

module.exports = router;
